// Created by WXX on 2022/1/9 19:08
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

/**
 * 执行用时：8 ms, 在所有 C++ 提交中击败了69.58%的用户
 * 内存消耗：10.5 MB, 在所有 C++ 提交中击败了62.08%的用户
 */
class Solution {
public:
    char slowestKey(vector<int>& releaseTimes, string keysPressed) {
        int s[26] = {0};
        for (int i = 0; i < keysPressed.size(); i++) {
            int &x = s[keysPressed[i] - 'a'];
            if (i == 0) x = releaseTimes[i];
            else x = max(x, releaseTimes[i] - releaseTimes[i - 1]);
        }

        char res = 'a';
        int t = s[0];
        for (int i = 0; i < 26; i++) {
            if (s[i] >= t) {
                res = i + 'a';
                t = s[i];
            }
        }
        return res;
    }
};

int main() {

    vector<int> releaseTimes = {9,29,49,50};
    cout << Solution().slowestKey(releaseTimes, "cbcd") << endl;  // c

    return 0;
}
